package com.huatai.manage.controller;

import com.huatai.common.api.R;
import com.huatai.manage.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName FileController
 * @Description TODO 文件控制器
 * @Author luoxc
 * @Date 2023/3/14 15:48
 * @Version 1.0
 */
@RestController
@RequestMapping("file")
@Api(value = "文件管理", tags = "文件管理")
public class FileController {

	@Autowired
	private FileService fileService;

	@PostMapping("upload")
	@ApiOperation(value = "上传文件", notes = "上传文件")
	public R uploadInputStream(@RequestParam("file") MultipartFile file) {
		return fileService.uploadInputStream(file);
	}

	@PostMapping("download")
	@ApiOperation(value = "下载文件", notes = "下载文件")
	public void download(@RequestParam("fileName") String fileName, HttpServletResponse response) {
		fileService.download(fileName, response);
	}

}
